$(document).ready(function(){
/*
auto_grow_area3=function(id){
//alert(id);
var textarea_auto=document.getElementById(id);
		//var a=textarea_auto.scrollHeight;
		var endline=textarea_auto.value.split("\n");
		//alert(andline.length);
		
		if(endline.length>1)
		{
			textarea_auto.style.overflowY='hidden';
			textarea_auto.style.height='auto';
			
			textarea_auto.rows=endline.length;
		}
		if(textarea_auto.value.length<60 && endline.length<=1) {
		textarea_auto.style.height='auto';textarea_auto.rows=3;}
		else if(textarea_auto.scrollHeight>16)
		{
			textarea_auto.style.overflowY='hidden';
			textarea_auto.style.height='auto';
			while(textarea_auto.offsetHeight>textarea_auto.scrollHeight )
			{textarea_auto.rows-=1;if(textarea_auto.rows<3)textarea_auto.rows=3;break;}
			while(textarea_auto.offsetHeight<textarea_auto.scrollHeight)
			{textarea_auto.rows+=1;}
		}
}

show_text_area_status=function(ops){
var idn=$('#'+ops.idn);
var classShow=$('.'+ops.classShow);
var textarea_auto=document.getElementById(ops.idn);
textarea_auto.style.backgroundColor='#ffffff';textarea_auto.style.color='#000';textarea_auto.style.height='auto';
if(idn.attr('rows')<3){
idn.attr('rows',3);}
classShow.show();}

$('.attLink').click(function(){
$('.boundLinkStatus').slideToggle('fast');
});

*/


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

waiting_getlink_status=function(url)
{
//alert('eee');
var list_img=[];
var defs={img:'img_status_posted_edit',show_edit:'panel_posted_status_edit_img',title:'title_post_status_edit',
meta:'noidung_post_status_edit',cllink:'link_posted_status',select_image:'select_image_link_status'};

var http=/^http:\/\//g;
if(url.match(http)!=null && url.match(http)!="")
{   //alert('Link Invalid');
	$('.'+defs.img).attr({src:ROOT+'public/images/loading.gif'});$('.'+defs.img).css({'padding':'40px'});
	$('.'+defs.img).show();
	//$('.loading_tag').show();
	var waiting_getlink_abort = $.ajax({
	//url:'../../application/modules/getlink/get_link_status.php',
	url:ROOT+'application/modules/getlink/get_link_status.php',
	data:{url:url,ki:'title'},
	dataType:'json',
	type:'post',
	success:function(B){
	//alert(B); return false;
	//alert(B.title);return false;
	$('.'+defs.title).html(B.title);
	$('.'+defs.meta).html(B.meta);
	$('.'+defs.cllink).html(B.link);
	$('.'+defs.show_edit).slideDown("fast");
	} 
	});
	
	var waiting_getlink_abort = $.ajax({
	url:ROOT+'application/modules/getlink/get_link_status.php',
	data:{url:url,ki:'img'},
	dataType:'json',
	type:'post',
	success:function(B){
	list_img=B.img;
	//alert(list_img.length);
	$('.'+defs.img).css({'padding':'0px'});
	(list_img.length>0) ?  $('.'+defs.img).attr({src:B.img[0]}) : $('.'+defs.img).hide();
	(list_img.length>0) ?  $('.'+defs.img).show() : $('.'+defs.img).hide();
	 (list_img.length>0) ? $('.'+defs.select_image).show() : $('.'+defs.select_image).hide();
	//$('.loading_tag').hide();
	} 
	});
	
	//end ajax
	var index_img=0;
	$('.next_img_status').click(function(){
	index_img++;
	(index_img>=list_img.length) ? index_img=0 : index_img;
	
	$('.'+defs.img).attr({src:list_img[index_img]});
	});
	$('.prev_img_status').click(function(){
	index_img--;
	(index_img<=0) ? index_img=list_img.length : index_img;
	$('.'+defs.img).attr({src:list_img[index_img]});
	});
	}
	else {//$('.loading_tag').hide();
	waiting_getlink_abort.abort();}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////




/*




var edit_click=0;
click_edit_=function(op){
	if(edit_click==0)
	{//alert('das');
	edit_click=1;
	var defs={text:'',cln:'none',inp:'none',w:100};
	var ops=$.extend(defs,op);
	if(ops.inp!='input')
	{	//alert(ops.w);
		$('.'+ops.cln).html('<textarea class=\'bd_all_dc\' style=\'min-height:50px;color:black;resize:auto;max-width:'+(ops.w-3)+'px;width:'+(ops.w-3)+'px;height:'+(ops.h-27)+';\'\'>'+ops.text+'</textarea>  ');
		$('.'+ops.cln+' textarea').focus();
		$('.'+ops.cln+' textarea').focusout(function(){
		var vall=$(this).val();
		$('.'+ops.cln).html(vall);
		edit_click=0;
		});
	}
	else 
	{
		$('.'+ops.cln).html('<input type=text class=\'bd_all_dc\' style=\' margin-top:0px; width:'+(ops.w-3)+';height:22px;\' value=\''+ops.text+'\' >');
		
		$('.'+ops.cln+' input').focus();
		$('.'+ops.cln+' input').focusout(function(){
		$('.'+ops.cln).html($(this).val());
		edit_click=0;
		});
	}
	}
}
reset_status=function(ops){
$('.'+ops.area).val('');$('.'+ops.link).text('');$('.'+ops.title).text('');$('.'+ops.nd).text('');$('.'+ops.showLink).hide();$('.'+ops.showLink+' input').val('');$('.'+ops.afterAtt).hide();
$('.'+ops.img).hide();$('.'+ops.bottomStatus).hide();
$('.val_textarea_status').css({'height':'23px','background-color':'transparent','color':'#dcdcdc'});
}
waiting_load_status_and_question=function(op){
	var defs={area:'none',uid:'none',pub:'none',img:'none',link:'none',nd:'none',title:'none',fid:'none'};
	var ops=$.extend(defs,op);
	var area=$('.'+ops.area),pub=$("input[name='"+ops.pub+"']"),img=$('.'+ops.img),link=$('.'+ops.link);
	var select_img=img.attr('src');
	if(select_img=="images/loading.gif" || $('.'+ops.img).css('display')=='none')
	{
		select_img="";
	}
	if(area.val()!="" || $('.'+ops.title).text()!="" || $('.'+ops.nd).text() != "")
	{
		$.ajax({
		url:'include/status/ajax_post_status.php',
		type:'post',
		data:{area:area.val(),pub:pub.val(),link:link.text(),img:select_img,fid:ops.fid,title:$('.'+ops.title).text(),nd:$('.'+ops.nd).text(),uid:ops.uid},

		dataType:'html',
		success:function(html){
		$('.bantin').prepend('<div class=\'ajax_postStatus\' style=\'display:none;\'>'+html+'</div>');
		$('.ajax_postStatus').slideDown();
		reset_status({area:ops.area,link:ops.link,title:ops.title,nd:ops.nd,img:ops.img,showLink:'boundLinkStatus',bottomStatus:'bottomStatus',afterAtt:'after_att'});		
		}
		
		});
	}
	else alert('Bai viet khong hop le...');
	return false;
}

var isctrl=false;
	$(document).keydown(function(e){
	if(e.keyCode==17)
	isctrl=true;
	}).keyup(function(e){
	if(e.keyCode==17)
	isctrl=false;
	});
waiting_load_comment=function(ops)
{
	var type="",urlAjax="";
	if(ops.type!=undefined)
	{	type=ops.type;
		if(ops.type=="Album")
		{
			urlAjax="include/layout/canhan/album_binhluan/ajax_post_album_binhluan.php";
		}
		else if(ops.type=="Image")
		{
			urlAjax="include/layout/lightBox/ImageBinhLuan/ajax_post_image_binhluan.php";
		}
	}
	else
	{
		var urlAjax="include/status/ajax_post_comment.php";
	}
	var id=$('#'+type+ops.id),img_id=$('#'+ops.img_id),comment_id=$('#'+ops.comment_id_show);
	img_id.show();
	comment_id.show();
	id.focusout(function(){
	if($(this).val()=="")
	{
		img_id.hide();
		
	}
	id.unbind('keypress');
	return false;
	});
	//id.focus(function(){
	var f=0;
	
	id.keypress(function(event){
	if(event.which==13)
	{
		
		//alert(a);
		if(isctrl==false)
		{
		//alert('-value-'+ id.val() + ' _idbaibviet_ ' +ops.id+ '_uid_ '+ops.uid);
		if(id.val().replace(/[\n|\r|\t]/g,'')!="" && id.val()!=null)
		{ 
			//alert(id.val());
			$.ajax({
				url:urlAjax,
				data:{nd:id.val().replace(/\n/g,'<br>'),idbaiviet:ops.id, uid:ops.uid},
				type:'post',
				dataType:'html',
				success:function(data){//alert(data);
					id.val('');
					id.attr('rows',0);
					id.css('height','22px');
					f++;
					$('#posted_comment'+type+ops.id).append(data);return false;
					},
					error:function (xhr, ajaxOptions, thrownError){
                    alert(xhr.status);
                    alert(thrownError);
					}
			});
		}
		else return false;
		}
		else {
		//alert('he');
		var rr=id.attr('rows');
		rr++;
		//alert(rr);
		id.css('height','auto');
		id.attr('rows',rr)
		id.val(id.val()+'\n');
		//alert(rr);
		}
	}
	
	});
	return false;
}
//end document
*/
});
